<?php
    if (COUNT($_POST))
    {
        $isnew = $this->get('new');
		if ($isnew)
		{
            $f = $this->get('firstname');
            $l = $this->get('lastname');
            $i = $this->get('institution');
            $e = $this->get('email');
            $a = $this->get('address');
            $c = $this->get('contact');
    		if (strlen($e) > 0){
                Connection::getConnect();
                $sql = "SELECT aid FROM login WHERE email='%s'";
                Connection::setQueryf($sql, $e);
                $fetch = Connection::fetch();
                if (!$fetch[0])
                {
    				do {
						$sql = "SELECT LEFT(UUID(), 12)";
                		Connection::setQuery($sql);
    					$u2 = Connection::fetch();
    					$sql = "SELECT aid FROM login WHERE userid='%s';";
                		Connection::setQueryf($sql, $u2[0]);
    					$u = Connection::fetch();
    				}while($u[0]);
    				$u = $p = $u2[0];
                    $sql = "INSERT INTO login(userid, password, first_name, last_name, email, institution, address, contact, type) VALUES('%s', MD5('%s'), '%s', '%s', '%s', '%s', '%s', '%s', 1)";
                    Connection::setQueryf($sql, $u, $p, $f, $l, $e, $i, $a, $c);
                }
                else
                {
                    echo "Email already taken.";
					exit;
                }
    		}
			exit;
		}
    }
?>